<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>基础数据管理-项目信息新增</title>
    <script src="/scripts/boot.js"></script>
</head>
<body class="bg-white">
<div id="viewForm">
    <div class="title-info mb-20"><span>基本信息</span></div>
    <table class="table-bg" border="0" cellpadding="1" cellspacing="1" style="width:100%;table-layout:fixed;">
        <colgroup>
            <col width="135px"></col>
            <col width="50%"></col>
            <col width="135px"></col>
            <col width="50%"></col>
        </colgroup>
        <tr>
            <td class="text-titlebg">
                <span class="color-red">*</span>区域
            </td>
            <td class="wpl">
            	<input type="hidden" class="mini-hidden" name="id" id="id"/>
            	<div id="area"></div>
                 <!--<input id="provinceCombo" class="mini-combobox w100" textField="province" valueField="id"-->
                       <!--url="/nation/getAllProvince" onvaluechanged="provinceChanged()" required="true" errorMode="none" >-->
                <!--<input id="cityCombo" name="cityId" class="mini-combobox w100" textField="city" valueField="id"-->
                       <!--onvaluechanged="cityChanged()" required="true" errorMode="none" onvalidation="onChoseValidation"-->
                       <!--requiredErrorText="请选择">-->
            </td>

            <td class="text-titlebg noEmpty"><span class="color-red">*</span>所属公司</td>
            <td>
			    <input name="affiliatedCompanyId" id="affiliatedCompanyId" class="mini-treeselect" style="width: 250px; margin-left: 10px;" showTreeIcon="true" valueField="id" textField="companyname"   parentField="parentid"   required="true" expandOnLoad="true"  errorMode="none" onvalidation="onChoseValidation" requiredErrorText="请选择"/>
            </td>
        </tr>
        <tr>
            <td class="text-titlebg"><span class="color-red">*</span>项目编码</td>
            <td>
                <input type="text" name="number" class="mini-textbox w250" required="true" maxLength="48" errorMode="none" onvalidation="onEnglishAndNumberValidation" requiredErrorText="请输入" vtype="maxLength:48"/>
            </td>
            <td class="text-titlebg"><span class="color-red">*</span>项目名称</td>
            <td>
           		<input type="text" id="name" name="name" class="mini-textbox w250" required="true" maxLength="50" onblur="view.valueChange" errorMode="none" onvalidation="onNullValidation" requiredErrorText="请输入" vtype="maxLength:50"/>
            </td>
        </tr>
        <tr>
            <td class="text-titlebg"><span class="color-red">*</span>项目简称</td>
            <td>
                <input type="text" name="abbreviation" class="mini-textbox w250" required="true" errorMode="none" maxLength="48" onvalidation="onNullValidation" requiredErrorText="请输入" vtype="maxLength:48"/>
            </td>
            <td class="text-titlebg"><span class="color-red">*</span>地块名称</td>
            <td>
           		<input type="text" name="earthName" class="mini-textbox w250" required="true" errorMode="none" onvalidation="onNullValidation" requiredErrorText="请输入" vtype="maxLength:48"/>
            </td>
        </tr>
        <tr>
            <td class="text-titlebg"><span class="color-red">*</span>项目地址</td>
            <td colspan="3">
                <input type="text" name="itemAddress" class="mini-textbox w250" required="true" maxLength="100" errorMode="none" onvalidation="onNullValidation" requiredErrorText="请输入" vtype="maxLength:100"/>
            </td>
        </tr>
    </table>
    <div class="title-info mb-20"><span>项目建设信息</span></div>
    <table class="table-bg" border="0" cellpadding="1" cellspacing="1" style="width:100%;table-layout:fixed;">
        <colgroup>
            <col width="135px"></col>
            <col width="50%"></col>
            <col width="135px"></col>
            <col width="50%"></col>
        </colgroup>
        <tr>
            <td class="text-titlebg">
                <span class="color-red">*</span>项目负责人
            </td>
            <td colspan="3">
<!--                 <input  name="functionaryId" id="functionaryId"    class="mini-hidden" /> -->
<!--                 <input onclick="view.selectPerson()"  id="functionaryName"  class="mini-textbox w250"  required="true" requiredErrorText="请选择"/> -->
<!--                 <input   name="functionaryId" id="functionaryId" class="mini-treeselect w250" onbeforenodeselect="common.beforenodeselect" expandOnLoad="true" showTreeIcon="true" valueField="id" textField="name" parentField="pid" required="true" errorMode="none" onvalidation="upChoseError" requiredErrorText="请选择"/> -->
                <!--<input type="text" name="functionaryId" class="mini-textbox w250" required="true" errorMode="none" onvalidation="onNullValidation" requiredErrorText="请输入" vtype="maxLength:48"/>-->
           
             <input id="functionaryId" name="functionaryId" textName="functionaryName" required="true" allowInput="false" class="mini-buttonedit w250" onbuttonclick="onButtonEdit"/>    
           
            </td>

            <!--<td class="text-titlebg title noEmpty">-->
<!--                 <span class="color-red">*</span>项目状态 -->
            <!--</td>-->
            <!--<td>-->
<!--                 <select id="status" name="status" class="mini-combobox w250" ajaxType="post" url="/dictionary/listValues?name=itemStatus" textField="value" valueField="id" errorMode="none" onvalidation="onChoseValidation" required="true" requiredErrorText="请选择"></select> -->
      <!--           <div name="status" class="mini-radiobuttonlist wpl"  repeatItems="1" repeatLayout="table" repeatDirection="vertical"  url="/dictionary/listValues?name=itemStatus" value="198" textField="value" valueField="id" ></div>
            	<input id = "status" name="status" class="mini-combobox w250" required="true" data="[{ id: '0', text: '在建' }, { id: '1', text: '暂停'}, { id: '2', text: '搁置'}, { id: '3', text: '结案'}]"  value="" errorMode="none" onvalidation="onChoseValidation" requiredErrorText="请选择"/>
                <select id="" name="status" class="mini-combobox w250" url="" textField="name" valueField="id" errorMode="none" onvalidation="onChoseValidation" required="true" requiredErrorText="请选择"></select>
         -->
            <!--</td>-->
        </tr>
        <!--<tr>-->
            <!--<td class="text-titlebg">-->
                <!--<span class="color-red">*</span>项目开始时间-->
            <!--</td>-->
            <!--<td>-->
                <!--<input name="itemStartDate"  id="itemStartDate" class="mini-datepicker w250" allowInput="false" errorMode="none" onvalidation="onChoseValidation" required="true" requiredErrorText="请选择"/>-->
            <!--</td>-->

            <!--<td class="text-titlebg title noEmpty">-->
                <!--<span class="color-red">*</span>项目结束时间-->
            <!--</td>-->
            <!--<td>-->
                <!--<input name="itemEndDate"  id="itemEndDate" class="mini-datepicker w250" allowInput="false" errorMode="none" onvalidation="onChoseValidation" required="true" requiredErrorText="请选择"/>-->
            <!--</td>-->
        <!--</tr>-->
        <!--<tr>-->
            <!--<td class="text-titlebg">-->
                <!--<span class="color-red">*</span>开工时间-->
            <!--</td>-->
            <!--<td>-->
                <!--<input name="workStartDate"  id="workStartDate" class="mini-datepicker w250" allowInput="false" errorMode="none" onvalidation="onChoseValidation" required="true" requiredErrorText="请选择"/>-->
            <!--</td>-->
            <!--<td class="text-titlebg title noEmpty">-->
                <!--<span class="color-red">*</span>竣工时间-->
            <!--</td>-->
            <!--<td>-->
                <!--<input name="workEndDate"  id="workEndDate" class="mini-datepicker w250" allowInput="false" errorMode="none" onvalidation="onChoseValidation" required="true" requiredErrorText="请选择"/>-->
            <!--</td>-->
        <!--</tr>-->
        <!--<tr>-->
            <!--<td class="text-titlebg">-->
                <!--<span class="color-red">*</span>开盘时间-->
            <!--</td>-->
            <!--<td>-->
                <!--<input name="openDate"  id="openDate" class="mini-datepicker w250" allowInput="false" errorMode="none" onvalidation="onChoseValidation" required="true" requiredErrorText="请选择"/>-->
            <!--</td>-->
            <!--<td class="text-titlebg title noEmpty">-->
                <!--<span class="color-red">*</span>封盘时间-->
            <!--</td>-->
            <!--<td>-->
                <!--<input name="sealDate"  id="sealDate" class="mini-datepicker w250" allowInput="false" errorMode="none" onvalidation="onChoseValidation" required="true" requiredErrorText="请选择"/>-->
            <!--</td>-->
        <!--</tr>-->
        <tr>
            <td class="text-titlebg noEmpty">目标客户</td>
            <td colspan="3" class="wp">
                <textarea name="targetClient" class="mini-textarea wtextarea" emptyText="" maxlength=200></textarea>
            </td>
        </tr>
        <tr>
            <td class="text-titlebg noEmpty">项目描述</td>
            <td colspan="3" class="wp">
                <textarea name="itemDescription"  class="mini-textarea wtextarea" emptyText="" maxlength=500></textarea>
            </td>
        </tr>
    </table>
    <div class="chose-toolbar">
        <a class="chose-button" onclick="CloseWindow('close')">取消</a>
        <a class="chose-button save-button" onclick="view.save()">保存</a>
    </div>
</div>
  
<script type="text/javascript">
// document.domain="localhost";
var post_flag,form,state,datas;

var view = {
    init: function () {
    	common.area.init("#area");
        post_flag = false; //设置一个对象来控制是否进入AJAX过程
        mini.parse();
        form = new mini.Form("#viewForm");
        common.company();
        /* common.loadTree({
            success : function(data){
                //获取评价人
                var functionaryId = mini.get("functionaryId");
                functionaryId.loadList(data, "id", "pid");
            }
        }); */
    },
 
//     selectPerson:function(){
//     	var affiliatedCompanyId = mini.get('affiliatedCompanyId').getValue();
//     	 mini.open({
//              url: "/common/person.html",
//              title: "选择负责人", width: 1100, height: 700,
//              onload: function () {
//              	var data = {"affiliatedCompanyId":affiliatedCompanyId,"status":0};//status如果是0代表此处是需要单选的
//              	var iframe = this.getIFrameEl();
//                 // iframe.contentWindow.view.SetData(data);
//              },
//              ondestroy: function (action) {
//             	 console.log(window.localStorage.getItem('data'))
            	 
//   //          	 mini.get('functionaryName').setValue(window.localStorage.getItem('data'));
//             	var info =  window.localStorage.getItem('data');
//             	if(info){
//             		var infos = info.split(',');
//             		 mini.get('functionaryId').setValue(infos[0]);
//             		 mini.get('functionaryName').setValue(infos[1]);
//             	}
//                  grid.reload();
//              }
//          });
//     }
//     ,
    valueChange:function(){
    	
        var id=mini.get("id").getValue();
        var affiliatedCompanyId=mini.get("affiliatedCompanyId").getValue();
        if(affiliatedCompanyId==""){
            return;
        }
        var name = mini.get("name").getValue();
        if(name==""){
            return;
        }
        
        $.ajax({
            url: "/item/checkItemName",
            data:{"id":id,"name":name,"affiliatedCompanyId":affiliatedCompanyId},
            type: "post",
            success: function (msg) {
    	
                if(msg==false){
                    mini.alert("该项目名称已经存在，请重新输入","提示",function(){
                  	  mini.get("name").setValue("");
                    	});
                }
            },
            error: function (errorMsg) {
                var msg  = JSON.parse(errorMsg.responseText);
                common.prompt(msg.message);
            }
        });
    },
    //保存
    save: function () {
        form.validate();
        if (form.isValid() == false) return;
        if (post_flag) return;
        var data = form.getData();//获取表单多个控件的数据
        var affiliatedCompanyId=mini.get("affiliatedCompanyId").getValue();
        var name = mini.get("name").getValue();
        $.ajax({
            url: "/item/checkItemName",
            data:{"id":data.id,"name":name,"affiliatedCompanyId":affiliatedCompanyId},
            type: "post",
            success: function (msg) {
            	
                if(msg==false){
                    mini.alert("该项目名称已经存在，请重新输入","提示",function(){
                  	  mini.get("name").setValue("");
                    	});
                }else{
                	
                	 
                     post_flag = true;
                     $.ajax({
                         url: (state=="new"?"/item/save":"/item/edit?id=" + data.id),
                         type: "post",
                         data: data,
                         success: function (msg) {
                             post_flag = false;
                             CloseWindow("ok");
                         },
                         error: function (errorMsg) {
                             post_flag = false;
                             var msg  = JSON.parse(errorMsg.responseText);
                             common.prompt(msg.message);
                         }
                     });
                }
                
            },
            error: function (errorMsg) {
                var msg  = JSON.parse(errorMsg.responseText);
                common.prompt(msg.message);
            }
        });
        
 
    },
//    数据展示
    SetData: function (data) {
        data = mini.clone(data);
        state = data.state;
        if(data.state=="edit"){
	        $.ajax({
	            url:"/item/info?id=" + data.id,
	            type: "post",
	            success: function (text) {
	                //跨页面传递的数据对象，克隆后才可以安全使用
	                datas = mini.decode(text);   //反序列化成对象
	                form.setData(datas);  //设置多个控件数据
	                mini.get("provinceCombo").setValue(datas.tSysNation.parentId);
	                mini.get("provinceCombo").setUrl("/nation/getAllProvince");
	                mini.get("cityCombo").setValue(datas.tSysNation.id);
	                mini.get("cityCombo").setUrl("/nation/getListByPid?pid="+datas.tSysNation.parentId);
                    setTimeout(function(){ mini.get("affiliatedCompanyId").setValue(datas.affiliatedCompanyId); },1000);
                  
	            }
	        });
        }else{
        	$('input[name=id]').val("");
        }
    }
};
 
// function onButtonEdit(e) {
//     var functionaryId = this;
//     mini.open({
//         url: "/dataBase/itemInfo/SelectTreeWindow.html",
//         showMaxButton: false,
//         title: "选择树",
//         width: 550,
//         height: 550,
//         ondestroy: function (action) {                    
//             if (action == "ok") {
                
//                 var iframe = this.getIFrameEl();
//                 var data = iframe.contentWindow.GetData();
//                 data = mini.clone(data);
//                 console.log(data)
//                 if (data) {
//                 	functionaryId.setValue(data.id);
//                 	functionaryId.setText(data.name);
//                 }
//             }
//         }
//     });            
     
// } 

 mini.parse();

function onButtonEdit(e) {
            var buttonEdit = e.sender;
            var win = mini.createTopSingle(TreeSelectWindow);
            win.set({
//                multiSelect: true,
//                showFolderCheckBox: true,
//                checkRecursive: true,
                url:"/org/loadTree",
                title: "选择人员",
                width: 520,
                height: 500
            });
            
            win.show();

            //初始化数据
            win.setData(null, function (action) {
                if (action == "ok") {
                    //获取数据
                    var node = win.getData();
                    if (node) {
                    	
                        buttonEdit.setValue(node.id);
                        buttonEdit.setText(node.name);
                    }
                }
            });
        }



view.init();
</script>
</body>
</html>